if(!jsx3.lang.Class.forName("ux.cdb.admin.system.user.userManage.userWizard.UserRoleSelect")) {
    jsx3.lang.Class.defineClass("ux.cdb.admin.system.user.userManage.userWizard.UserRoleSelect",
            ux.megatron.gui.WizardPanel,
            null,
            function (block) {
                /**
                 * instance initializer
                 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
                 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
                 */
                block.prototype.arrmtxName=["mtxSel","mtxunSel"];
                block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
                    //call constructor for super class (the super expects the name of the object and the function that it is an instance of)
                    this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
                };
                block.prototype.initialize = function(msg) {
                     var me = this;
                     this.wizard = this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard");
                     if(this.wizard.Operation=="Edit"){
                         try{
                             ux.megatron.Main.getServer().getCache().setDocument(this.getMatrixByName(this.arrmtxName[0]).getXMLId(), ux.cdb.admin.system.user.UserManage.RoleList.selectRoleList[0]);
                             this.getMatrixByName(this.arrmtxName[0]).repaint();
                             ux.megatron.Main.getServer().getCache().setDocument(this.getMatrixByName(this.arrmtxName[1]).getXMLId(),ux.cdb.admin.system.user.UserManage.RoleList.unselectRoleList[0]);
                             this.getMatrixByName(this.arrmtxName[1]).repaint();
                         }catch(ex){
                     /* @JSC :: begin DEBUG */
                             jsx3.log(ex);
                    /* @JSC :: end */
                         }
                     }
                     else if(this.wizard.Operation=="Insert"){
						var params = [
							ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.systemUserTypeCode,
							ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.userRelatedOrg
						];
                     /* @JSC :: begin DEBUG */
						jsx3.log('UserRoleSelect params : ' + params);
                    /* @JSC :: end */
                        ux.megatron.util.Dwr.callDwr("UserMgrUCC", "getRoleListByCondition", params, me, me.callBackDwr, "UserMgrUCC");
                     }
                }

                block.prototype.callBackDwr = function(dwrObject){
                   try{
                         var cdfDoc = ux.megatron.util.Dwr.toCdfDocument(dwrObject.content.data, "jsxroot", {"sysRoleId": "jsxid"});
                         //alert(this.getMatrixByName("unSelectedRoleMX"));
                         this.getServer().getCache().setDocument(this.getMatrixByName(this.arrmtxName[1]).getXMLId(), cdfDoc);
                         this.getMatrixByName(this.arrmtxName[1]).repaint();
                        }catch(ex){
                     /* @JSC :: begin DEBUG */
                            jsx3.log(ex);
                    /* @JSC :: end */
                    }
               }
                block.prototype.getMatrixByName = function(materixName){
                    return this.getDescendantOfName(materixName);
                };
                block.prototype._removeRole=function(){
                   var nodes=this.getMatrixByName(this.arrmtxName[0]).getSelectedNodes();
                   var iterator=nodes.iterator();
                   while(iterator.hasNext()){
                       var temp=iterator.next();
                         ux.megatron.Main.getServer().getCache().getDocument(this.getMatrixByName(this.arrmtxName[1]).getXMLId()).appendChild(temp);
                         ux.megatron.Main.getServer().getCache().getDocument(this.getMatrixByName(this.arrmtxName[0]).getXMLId()).removeChild(temp);
                   }
                   try{
                    this.getMatrixByName(this.arrmtxName[0]).repaint();
                    this.getMatrixByName(this.arrmtxName[1]).repaint();
                   }catch(ex){
                     /* @JSC :: begin DEBUG */
                       jsx3.log(ex);
                    /* @JSC :: end */
                   }
                };
                block.prototype._addRole=function(){
                   var nodes=this.getMatrixByName(this.arrmtxName[1]).getSelectedNodes();
                   var iterator=nodes.iterator();
                   while(iterator.hasNext()){
                       var temp=iterator.next();
                         ux.megatron.Main.getServer().getCache().getDocument(this.getMatrixByName(this.arrmtxName[0]).getXMLId()).appendChild(temp);
                         ux.megatron.Main.getServer().getCache().getDocument(this.getMatrixByName(this.arrmtxName[1]).getXMLId()).removeChild(temp);
                   }
                   try{
                    this.getMatrixByName(this.arrmtxName[0]).repaint();
                    this.getMatrixByName(this.arrmtxName[1]).repaint();
                   }catch(ex){
                     /* @JSC :: begin DEBUG */
                       jsx3.log(ex);
                    /* @JSC :: end */
                   }
                }
                block.prototype.modified=function(SysRolelist1,SysRolelist2){
                    if(SysRolelist1.length!=SysRolelist2.length){
                        return true;
                    }else{
                        for(var i=0;i<SysRolelist1.length;i++){
                            var flag=false;
                            for(var j=0;j<SysRolelist2.length;j++){
                                if(SysRolelist1[i].roleName!=SysRolelist2[j].roleName){
                                    flag=true;
                                }else{
                                    flag=false;
                                    break;
                                }
                            }
                            if(flag){
                                return true;
                            }
                        }
                        return false;
                    }
                }
                block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    return null; // return "NONE" to not next panels
                }

                block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                   if(this.wizard.Operation=="Edit"){
                       this.checkmodify();
                   }
                    return null; // return "NONE" to not advance panels
                }

                block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    return null; // return "NONE" to not last status
                }

                block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                      this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
                      return null; // return "NONE" to not advance panels
                }

              block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                  /*var nodes=this.getMatrixByName(this.arrmtxName[0]).getSelectedNodes();
                  var lbl = this.wizard.get("lblMessage");
                   if(nodes.size() >= 1) {
                     lbl.setText('',true);
                    this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
                    try{
                       //console.info(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO);
                    }catch(ex){
                        console.info(ex);
                    }
                    //call the DWR method to save data
                     return null; // return "NONE" to not advance panels
                  } else {
                    var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@selectRole");
                    lbl.setColor('red');
                   lbl.setText(tip,true);
                   return false;
                 }*/
                  try{
                      if(this.wizard.Operation=="Insert"){
                          var lbl = this.wizard.get("lblMessage");
                          ux.cdb.admin.system.user.userManage.userWizard.UserInfo.stepCheck(lbl,this);
                      }else{
                             this.checkmodify();
                             /* @JSC :: begin DEBUG */
                             console.log("step3 finish start");
                             console.log(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO);
                             /* @JSC :: end */
                            if(ux.cdb.admin.system.user.UserManage.Userchanged||ux.cdb.admin.system.user.UserManage.Orgchanged||ux.cdb.admin.system.user.UserManage.Rolechanged){
                               var me = this;
							   ux.megatron.util.Dwr.callDwr("UserMgrUCC", "updateUserInfo", [ux.cdb.admin.system.user.UserManage.UserInfoReqUIO], this, function(dwrobj){
                                   //console.log(dwrobj);
                                   if(dwrobj!=null){
                                       if(dwrobj.res.flag=="1"){
                                           //this.wizard.onClose();
                                           ux.cdb.admin.Cache.remove(ux.cdb.admin.dataautomate.GenericDetail.User+":"+ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.sysUserId);
                                           var um=ux.megatron.Main.getServer().getJSXByName("blkWorld");
                                           um.LoadUsers();
                                           //return;
                                       }
                                   }
		                           me.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
                               //add some code to catch exception when save
                                }, "UserMgrUCC");
                           }else{
							   me.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
						   }
                      }
                  }catch(ex){
                      /* @JSC :: begin DEBUG */
                      jsx3.log(ex);
                      /* @JSC :: end */
                  }
               }
                block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    return null; // return "NONE" to not advance panels
                }

                block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
                    if(!this.getChild(0)) {
                        var me = this;
                        ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/system/user/userWizard/step3/ui/UserRoleSelectContent.xml", me, me.initialize);
                    }
                    return null; // return "NONE" to not advance panels
                }

                block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
                    return null; // return "NONE" to not advance panels
                }
              /*@
              *@  this function is to check ....
              @*/
                block.prototype.onStepJump=function(objWIZARD, objSTEP, objEVENT, strCURRENTPANEL){
                    var me=this;
                     var lbl = this.wizard.get("lblMessage");
                     var mxRole=this.wizard.get("mtxSel");
                     var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step3@unfinish");
                     if((mxRole.getXML().getChildNodes().size()==0)){
                            lbl.setColor('red');
                            lbl.setText(tip,true);
                            return "NONE";
                     }else{ 
                          setTimeout(function(){
                              me.checkmodify();
                          },0);
                          return null;
                     }
                }
                block.addUserInfo=function(){
                      

                }
        
        block.prototype.onSaveData = function() {
          var me = this;
          var roleList = [];
          
          var SysRole = {
            roleDesc: 'roleDesc',
            roleType:'roleType',
            roleName:'roleName',
            sysRoleId:9999,
            parentRoleId:8888
          };
          roleList.push(SysRole);
    
          var data = {
            userName:'userName',
            logonName:'logonName',
            logonPwd:'logonPwd',
            userRelatedOrg:'userRelatedOrg',
            userStatusIndicator:'userStatusIndicator',
            userDesc:'userDesc',
            systemUserTypeCode:'systemUserTypeCode',
            certTypeCode:'certTypeCode',
            certId:'certId',
            ownedDepartmentCode:'ownedDepartmentCode',
            ownedDepartmentName:'ownedDepartmentName',
            phoneNbr:'phoneNbr',
            mobileNbr:'mobileNbr',
            email:'email',
            selectRoleList:roleList
          }
          
          var params = [];
          params.push(data);
          ux.megatron.util.Dwr.callDwr("UserMgrUCC", "addUserInfo", params, me, me.callBackBySaveData, "UserMgrUCC");
        }
    
        block.prototype.callBackBySaveData = function(data) {
          this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
        }
        block.prototype.checkmodify=function(){
             var mxRole=this.wizard.get("mtxSel");
             var it=mxRole.getXML().getChildNodes().iterator();
             var SysRolelist=[];
             while(it.hasNext()){
                var role=new Object();
                var item=it.next();
                role.roleName=item.getAttribute("roleName");
                role.sysRoleId=parseInt(item.getAttribute("jsxid"));
                role.parentRoleId=isNaN(parseInt(item.getAttribute("parentRoleId")))?0:parseInt(item.getAttribute("parentRoleId"));
                role.roleType=null;
                role.roleDesc=item.getAttribute("roleDesc");
                SysRolelist.push(role);
            } 
            /* @JSC :: begin DEBUG */
            console.log("step3 value changed:"+this.modified(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.selectRoleList,SysRolelist));
            /* @JSC :: end */
            if(this.modified(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.selectRoleList,SysRolelist)){
                   ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.selectRoleList=[];
                   ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.selectRoleList=SysRolelist;
                   console.log(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.selectRoleList);
                   ux.cdb.admin.system.user.UserManage.Rolechanged=true;
            }
        }
      }
    );
}
